package com.yinhe.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.system.domain.YhEnterprise;
import com.yinhe.system.service.IYhEnterpriseService;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;

/**
 * 承制单位信息Controller
 * 
 * @author yinhe
 * @date 2022-07-13
 */
@RestController
@RequestMapping("/system/enterprise")
public class YhEnterpriseController extends BaseController
{
    @Autowired
    private IYhEnterpriseService yhEnterpriseService;

    /**
     * 查询承制单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:enterprise:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhEnterprise yhEnterprise)
    {
        startPage();
        List<YhEnterprise> list = yhEnterpriseService.selectYhEnterpriseList(yhEnterprise);
        return getDataTable(list);
    }

    /**
     * 导出承制单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:enterprise:export')")
    @Log(title = "承制单位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhEnterprise yhEnterprise)
    {
        List<YhEnterprise> list = yhEnterpriseService.selectYhEnterpriseList(yhEnterprise);
        ExcelUtil<YhEnterprise> util = new ExcelUtil<YhEnterprise>(YhEnterprise.class);
        util.exportExcel(response, list, "承制单位信息数据");
    }

    /**
     * 获取承制单位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:enterprise:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhEnterpriseService.selectYhEnterpriseById(id));
    }

    /**
     * 新增承制单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:enterprise:add')")
    @Log(title = "承制单位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhEnterprise yhEnterprise)
    {
        return toAjax(yhEnterpriseService.insertYhEnterprise(yhEnterprise));
    }

    /**
     * 修改承制单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:enterprise:edit')")
    @Log(title = "承制单位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhEnterprise yhEnterprise)
    {
        return toAjax(yhEnterpriseService.updateYhEnterprise(yhEnterprise));
    }

    /**
     * 删除承制单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:enterprise:remove')")
    @Log(title = "承制单位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhEnterpriseService.deleteYhEnterpriseByIds(ids));
    }
}
